﻿@using WqLunTan.Areas.Manage.Models

@model PageModel

@{
    var controller = ViewContext.RouteData.Values["Controller"].ToString();
    var action = ViewContext.RouteData.Values["Action"].ToString();
    var page = Model;
}

<div class="paging text-right">
    <div class="pagination">
        @{
            if (page.PageCount <= 1)
            {
                // 不需要翻页
                <span class="text-muted">共一页</span>
            }
            else
            {
                var start = page.CurrentPageIndex - (page.PageButtonCount / 2);
                if (start <= 1 && page.PageCount > 2)
                {
                    start = 2;
                }

                var end = page.CurrentPageIndex + (page.PageButtonCount / 2);
                if (end >= page.PageCount)
                {
                    end = page.PageCount;
                }

                <table class="table table-responsive">
                    <tr>
                        <td>
                            <div style="height:30px;line-height:30px;">共<span style="color:darkgreen;">@(page.PageCount)</span>页</div>
                        </td>

                        @if (page.PageCount > 10)
                        {
                            <td>
                                <input class="form-control" type="number" id="page-index-number" value="@(page.CurrentPageIndex)" min="1" max="@(page.PageCount)" />
                            </td>
                            <td>
                                <button type="button" class="btn btn-primary btn-sm btn-goto" onclick="javascript:location.href='@Url.Action(action, controller)'+ '?pageIndex=' +$('#page-index-number').val()">跳转</button>
                            </td>
                        }

                        <td>
                            <div class="btn-group" data-toggle="buttons-radio">
                                <button type="button" class="btn btn-primary btn-sm" onclick="javascript:location.href='@Url.Action(action, controller, new { pageIndex = 1 })'">首页</button>

                                @{
                                    if (start > 0 && start <= end)
                                    {
                                        for (int i = start; i < end; i++)
                                        {
                                            <button type="button" class="btn btn-sm @(i==page.CurrentPageIndex? "btn-success":"btn-primary")" onclick="javascript:location.href='@Url.Action(action, controller, new { pageIndex = i })'">@(i)</button>
                                        }
                                    }
                                }

                                <button type="button" class="btn btn-primary btn-sm" onclick="javascript:location.href='@Url.Action(action, controller, new { pageIndex = page.PageCount })'">尾页</button>
                            </div>
                        </td>
                    </tr>
                </table>
            }
        }
    </div>
</div>